//
//  AVGUserAount.swift
//  33-
//
//  Created by mac on 16/7/24.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

//用户账户模型

class AVGUserAount: NSObject {
    
    /// AccessToken,用于获取用户数据
  @objc private  var access_token: String?
    
    /// access_token的生命周期，单位是秒数。
    var expires_in: NSTimeInterval = 0
    
    /// 授权用户的UID，
    var uid: String?
    
    
    /// 过期时间,NSDate类型,方便后面比较
    var expiresDate: NSDate?


    init(dict:[String: AnyObject ]) {
//        access_token = dict["access_token"] as! String
//        expires_in  =  dict["expires_in"]  as! NSTimeInterval
//        uid  =  dict["uid"]  as! String
        
         super.init()
         setValuesForKeysWithDictionary(dict)
    }
    // 字典中的key在模型中找不到对应的属性,如果不实现这个方法就会崩溃
    override  func  setValue(value: AnyObject?, forUndefinedKey key: String) {
        print("forUndefinedKey:\(key )")
    }
    
    //对象打印
    /// 对象打印
    override var description: String {
        get {
            return "access_token: \(access_token), expires_in: \(expires_in), uid: \(uid),expiresDate:\(expiresDate)"
        }
    }
    //归档和解档
    required  init?(code nscode:NSCoder)
    {
    access_token = nscode.decodeObjectForKey("access_token") as? String
    expires_in =  nscode.decodeDoubleForKey("expires_in")
    uid = nscode.decodeObjectForKey("uid") as?  String
    expiresDate = nscode.decodeObjectForKey("expiresDate") as?
        NSDate
    
    super.init()
    }
    func  encodeWithCoder(acode:NSCoder)
    {
    acode.encodeObject(access_token, forKey: "access_token")
    acode.encodeObject(expires_in, forKey: "expires_in")
    acode.encodeObject(uid, forKey: "uid")
    acode.encodeObject(expiresDate, forKey: "expiresDate")
    }
}
